package com.yrw.classdemo;

import java.util.HashSet;
import java.util.Scanner;
import java.util.StringJoiner;

public class Homework02 {
    public static void main(String[] args) {
        int num=0;
        System.out.println("请输入一个正整数：");
        Scanner sc=new Scanner(System.in);
        num=sc.nextInt();
        HashSet<Integer> result=test(num);
        if (result.contains(-1)){
            System.out.println("输入有误！");
            return;
        }
        StringJoiner stringJoiner=new StringJoiner(",","","");
        for (Integer i : result) {
            stringJoiner.add(i.toString());
        }
        System.out.println(num+" it’s  factors are "+ stringJoiner);

    }
    public static HashSet<Integer> test(int num){
        HashSet<Integer> result=new HashSet<>();
        result.add(1);
        if (num<=0){
            result.add(-1);
        }
        if (num==1){
            result.add(1);
        }

        for (int i=2;i<num;i++){
            if (num%i==0){
                result.add(i);
            }
        }
        return result;
    }
}
